class Iblog::ArticlesController < ApplicationController
	before_filter :find_article, :only => [:show, :edit, :update, :destroy]

	def index
		@articles = Article.paginate(:page => params[:page], :per_page => 5).order("created_at DESC")
	end

	def new
		@article = Article.new
	end

	def show
		# @article = Article.find(params[:id])		
	end

	def create
		@article = Article.new(params[:article])

	  	respond_to do |format|
	    	if @article.save
	      		format.html { 
		      		redirect_to iblog_articles_url, :notice => 'article was successfully created.'
		      	}
	      		format.xml  { render :xml => @article,
	                    :status => :created, :location => @article }
	    	else
	     	 	format.html { render :action => "new" }
	     	 	format.xml  { render :xml => @article.errors,
	                    :status => :unprocessable_entity }
	        end
	    end
	end

	def edit
		
	end

	def update
		if @article.update_attributes(params[:article])
			redirect_to iblog_article_url(@article)
			flash[:notice] = "update successfully"	
		else
			render :action => :edit		
		end		
	end

	def destroy
		@article.destroy
		redirect_to iblog_articles_url
	end

	protected
	def find_article
		@article = Article.find(params[:id])		
	end
end
